package com.mytest.test;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Item {

    private Integer id = 20;

    Lock lock = new ReentrantLock();

    public void getItem() {
        boolean flag = lock.tryLock();
        if (!flag) {
            return;
        }
        try {
            System.out.println(Thread.currentThread().getName() + "->" + id--);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }
}
